Repository navigation
perf: the panel's conversation list totals each conversation once, so its time grows with the messages, not their square - #20
Merged
Conversation
… its time grows with the messages, not their square conversations ran three subqueries over every side for each message, not for each conversation. With one person in 20,000 messages with 50 others it took 29.6 s; it now takes 0.4 s. At 5,000 messages it went from 2.2 s to 0.1 s. The output is the same. A new test checks waiting, waiting_since and sides per conversation, which no test did: without it, a waiting_since taken from read messages too, or one conversation's totals shown on another, passed every test.
BukeLy
force-pushed
the
perf/conversations-linear
branch
from
November 23, 2026 06:38
f1a83c6 to
210e507
Compare
BukeLy
marked this pull request as ready for review
November 23, 2026 06:42
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The panel's conversation list takes 0.4 s at 20,000 messages instead of 29.6 s.
One person in that many messages with 50 others, all unread. Postgres 18 in Docker, best of 3 calls.
conversationsran three subqueries over thesidesCTE once per message, not once per conversation.EXPLAIN ANALYZEat 5,000 messages showedCTE Scan on sides s (... rows=100.00 loops=5000)under SubPlans 4, 5 and 6.totalsCTE aggregatessidesonce, grouped by key, and thedistinct on (x.key)query joins to it. Every node in the new plan runs withloops=1. The only SubPlan left is the hashedid in (select message_id from deliveries ...)filter in_MINE, which runs once.minewas sent by the person or delivered to them, so every key has totals.mailbox.pytomessages.py, so the change now lands inmessages.py.Test plan
uv run pytest -q: 74 passed, 1 skipped (the 73 from before plus one new test).test_each_conversation_counts_only_what_waits_in_it, checks sides, waiting and waiting_since in two conversations. I broke the query four ways and it failed every time. Without it, two of those breaks passed every test: waiting_since taken from read messages too, andtotalsjoined ontrue.conversationsfor 21 people, 118 conversations, returned identical results before and after.uvx ruff@0.17.6 check .anduvx ruff@0.17.6 format --check .pass.